package com.usian.search.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.search.dto.UserSearchDto;
import com.usian.model.search.pojos.ApAssociateWords;
import com.usian.search.mapper.ApAssociateWordsMapper;
import com.usian.search.service.ApAssociateWordsService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @Auther:ASS
 * @Date:2023/3/9 20:36
 */
@Service
public class ApAssociateWordsServiceImpl extends ServiceImpl<ApAssociateWordsMapper, ApAssociateWords> implements ApAssociateWordsService {



    /**
     * 联想词
     *
     * @param dto
     * @return
     */
    @Override
    public ResponseResult search(UserSearchDto dto) {

        if (dto.getPageSize()>50){
            return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
        }


        //模糊查询
        IPage pageParam=new Page(0,dto.getPageSize());

        List<ApAssociateWords> list= list();
        IPage page = page(pageParam, Wrappers.<ApAssociateWords>lambdaQuery().like(ApAssociateWords::getAssociateWords,
                dto.getSearchWords()));
        return ResponseResult.okResult(page.getRecords());
    }
}
